import React from 'react'
import {Route,Switch,Redirect} from 'react-router-dom'
const RouterView = (props)=>{
    console.log(props.routes);  

    let reds = props.routes.filter(item=>item.redirect);
    let coms = props.routes.filter(item=>item.component)
    return <Switch>
        {
            coms.map((item,index)=>{
                console.log(item);   
                return <Route key={index} path={item.path} render={routerProps=>{
                    if(item.children){  
                        return <item.component {...routerProps} routes={item.children}/>
                    }else{  
                        return <item.component {...routerProps}/>
                    } 
                }}></Route>
            })
        }
        {
            reds.map((item,index)=>{
                return <Redirect key={index} to={item.redirect}></Redirect>
            })
        }
    </Switch>
}
export default RouterView